home *** CD-ROM | disk | FTP | other *** search
/ MacWorld 1999 January - Disc 2 / Macworld (1999-01) (Disk 2).dmg / Shareware World / Anti Virus / AntiGax v1.2 / Source / AntigaxCommon.c < prev    next >
Text File  |  1998-10-04  |  3KB  |  120 lines

  1. char RepairApp(short rev);
  2. void WriteString(short fie, uchar *str);
  3.  
  4.  
  5. extern FSSpec    *lantana;
  6. extern short    orrez;
  7. extern Boolean    check_only;
  8.  
  9. char RepairApp(short rev)
  10. {
  11. Handle    mdh,    menuh;
  12. Str255    stoop;
  13. Str63    nuname;
  14. ulong    ule;
  15. long    mdlen,    mdglobs,    l,    mdencend,    menusz;
  16. short    nmdf,    i,    menid,    mdid,    j;
  17. uchar    obka;
  18.  
  19. nmdf=Count1Resources('MDEF');
  20. if(!nmdf) return 0;
  21.  
  22. for(i=0;i<nmdf;i++)
  23.     {
  24.     mdh=Get1IndResource('MDEF',i+1);
  25.     if(!mdh) continue;
  26.     
  27.     if( ((short*)(*mdh))[4] == 'JS' ) break;
  28.     }
  29.  
  30. if(i==nmdf) return 0;
  31.  
  32. GetResInfo(mdh,&mdid,&ule,stoop);
  33.     // WE don't give a Str63 or whatever the virus gives for the name arg in its call!
  34.  
  35. /* OK, we have a definitely infected app now */
  36.  
  37. if(check_only) return 1;
  38.  
  39. /* First find the char it's obfuscated with, and unobfuscate it */
  40. mdlen=GetHandleSize(mdh);
  41. mdglobs=mdlen-0x1E2;
  42. obka=*(mdglobs + 0x2A + *mdh);
  43.  
  44. mdencend=*(short*)(2+*mdh) + 2;
  45. for(l=0x0A;l<mdencend;l++) (*mdh)[l]^=obka;
  46.  
  47. /* now get the affected MENU id */
  48. menid=*(short*)(0x0A + *mdh);
  49.  
  50. /* make sure that menu is still there and full of f's ... well as much as it checks */
  51. menuh=Get1Resource('MENU',menid);
  52. if(!menuh || **menuh!='f')
  53.     {
  54.     BlockMoveData(lantana->name,nuname,64);
  55.     BlockMoveData(".bad",&nuname[nuname[0]+1],4);    nuname[0]+=4;
  56.     FSpRename(lantana,nuname);
  57.     
  58.     if(orrez)
  59.         {
  60.         UseResFile(orrez);
  61.         ParamText(lantana->name,nil,nil,nil);
  62.         Alert(131,nil);
  63.         }
  64.     return -1;
  65.     }
  66.  
  67. /* now copy the proper data back into it */
  68. menusz=GetHandleSize(menuh);
  69. BlockMoveData(0x0A+*mdh,*menuh,menusz);
  70. ChangedResource(menuh);
  71.  
  72. /* Now find the lowest-ID menu which was using the virus MDEF as their MDEF and
  73. set them back to 0. There is a small chance this will make a menu using a custom
  74. MDEF which is in another file go back to using the std MDEF (if it installed at
  75. this ID), but these apps would have stuffed up completely when run as infected. */
  76.  
  77. nmdf=Count1Resources('MENU');
  78. menid=0x7FFF;    // works for them
  79. for(i=1;i<=nmdf;i++)
  80.     {
  81.     menuh=Get1IndResource('MENU',i);
  82.     if(!menuh) continue;
  83.     
  84.     if( ((short*)*menuh)[3]!=mdid )
  85.         {
  86.         HPurge(menuh);            // happy now?
  87.         continue;
  88.         }
  89.     
  90.     GetResInfo(menuh,&j,&ule,stoop);
  91.     if(menid>j) menid=j;
  92.     }
  93.  
  94. if(menid<0x7FFF)    // just ignore it if we didn't find one I think...
  95.     {
  96.     menuh=Get1Resource('MENU',menid);
  97.     ((short*)*menuh)[3]=0;
  98.     ChangedResource(menuh);
  99.     }
  100.  
  101. /* And finally, it's time to say goodbye to our favourite resource... */
  102. RemoveResource(mdh);
  103. DisposeHandle(mdh);
  104. UpdateResFile(rev);
  105. /* Good riddance! */
  106.  
  107. return 1;
  108. }
  109.  
  110.  
  111. void WriteString(short fie, uchar *str)
  112. {
  113. long    sz;
  114.  
  115. if(!fie || fie==-1) return;
  116.  
  117. sz=str[0];
  118. FSWrite(fie,&sz,str+1);
  119. }
  120.